<template>
    <div class="container">
        <!-- <v-toolBar
            :fullPath='postData.opera'
            :tableColumns='tableColumns'
            @changeLie='getChangeLie'
            @getSearchIPArr='getToolBarSearchIPArr'
            @getSearchIP='getToolBarSearchIP'>
        </v-toolBar> -->
        <el-table
            v-loading="loading"
            element-loading-text="拼命加载中"
            element-loading-spinner="el-icon-loading"
            :data="tableData"
            :fit='true'
            border
            style="width: 100%">
            <template v-for="(item) in tableColumns">
                <el-table-column
                    :prop="item.prop"
                    :label="item.label"
                    
                    v-if="item.isShow"
                    :key="item.prop">
                </el-table-column>
            </template>
        </el-table>
        <!-- <v-pagination
            :dataTotal="dataTotal" 
            :curPage="postData.curPage" 
            :pageSize="postData.pageSize" 
            @getCurPage="getPaginationCurPage"
            @getPageSize="getPaginationPageSize">
        </v-pagination> -->
    </div>
</template>

<script>
import { DBADG } from '@/api/index.js'
import vPagination from 'common/Pagination.vue';
import vToolBar from 'common/toolbar/Toolbar.vue';
import tableColumns from './DataGuardTableColumns.js';
import bus from 'common/bus.js';
import Isnull from '@/utils/ObjectIsNull'

export default {
    name: 'dataGuard',
    props:{
        info:null
    },
    components: {
        vPagination, vToolBar
    },
    // watch:{
    //    'info':function(n,o){
    //        console.log(o,n)
    //        this.getTableData();
    //    } 
    // },
    data() {
        return {
            postData: {
                opera: 'dataGuard',
                curPage: 1,
                pageSize: 20,
                sort: {
                    sortColumn: '',
                    sortOrders: ''
                },
                filtersType: 'fuzzyquery',
                filters: {}
            },
            tableData: [],
            dataTotal: 0,
            tableColumns: tableColumns,
            SearchIPArr: [],
            searchJson: {},
            SearchIP: '',
            timerName: 'MonitorInfoDataBaseOracleDG',
            timerEventName: 'timerMonitorInfoDataBaseOracleDG',
            // timerInterval: 1000 * 60,
            loading: false
        }
    },
    created() {
        this.getTableData();
        
    },
    computed: {
        postDataFn() {
            return {
                postData: JSON.stringify(this.postData)
            }
        },
        timerInterval(){
            return Number(this.$store.state.pageRefresh)*1000
        }
    },
    methods: {
        getTableData(){
            this.loading = true;
            
            DBADG(
                {ip:this.info.ip,sid:this.info.dbSid}
            ).then((_) => {
                if(!Isnull(_)){
                    this.tableData=[_]
                }else{
                    this.tableData=[]
                }
                

                this.loading = false;
            });
        },
        // getPaginationCurPage(val) {
        //     this.postData.curPage = val;
            
        //     this.getTableData();
        // },
        // getPaginationPageSize(val) {
        //     this.postData.curPage = 1;
        //     this.postData.pageSize = val;

        //     this.getTableData();
        // },
        getToolBarSearchIPArr(arr) {
            this.SearchIPArr = arr;

            this.postData.curPage = 1;
            if (this.SearchIPArr.length > 0) {
                this.postData.filters = {
                    ip: this.SearchIPArr
                };
            } else {
                this.postData.filters = {};
            }

            this.getTableData();
        },
        getToolBarSearchIP(str){
            this.SearchIP = str;
            this.postData.curPage = 1;
            this.postData.filters = {
                ip: this.SearchIP
            };
            this.getTableData();
        },
        getChangeLie(val) {
            this.tableColumns.map((item, index) => {
                item.isShow = val.includes(item.label);
            });
        }
    },
    
    beforeDestroy() {
       
    },
}
</script>

<style scoped>
    .el-table .warning-row {
        background: oldlace;
    }
    .el-table .success-row {
        background: #f0f9eb;
    }
</style>